package com.ruoyi.degree.service.Impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.degree.domain.BizSchoolsDepartment;
import com.ruoyi.degree.mapper.BizSchoolsDepartmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.degree.mapper.BizSchoolsProfessionsMapper;
import com.ruoyi.degree.domain.BizSchoolsProfessions;
import com.ruoyi.degree.service.IBizSchoolsProfessionsService;

/**
 * 院校展示Service业务层处理
 *
 * @author ruoyi
 * @date 2025-07-25
 */
@Service
public class BizSchoolsProfessionsServiceImpl implements IBizSchoolsProfessionsService
{
    @Autowired
    private BizSchoolsProfessionsMapper bizSchoolsProfessionsMapper;
    @Autowired
    private BizSchoolsDepartmentMapper bizSchoolsDepartmentMapper;

    @Autowired
    private com.ruoyi.degree.service.IBizSchoolsProfessionsClassesService bizSchoolsProfessionsClassesService;

    /**
     * 查询院校展示
     *
     * @param id 院校展示主键
     * @return 院校展示
     */
    @Override
    public BizSchoolsProfessions selectBizSchoolsProfessionsById(Long id)
    {
        return bizSchoolsProfessionsMapper.selectBizSchoolsProfessionsById(id);
    }

    /**
     * 查询院校展示列表
     *
     * @param bizSchoolsProfessions 院校展示
     * @return 院校展示
     */
    @Override
    public List<BizSchoolsProfessions> selectBizSchoolsProfessionsList(BizSchoolsProfessions bizSchoolsProfessions)
    {
        List<BizSchoolsProfessions> list = bizSchoolsProfessionsMapper.selectBizSchoolsProfessionsList(bizSchoolsProfessions);
        for (BizSchoolsProfessions bizSchoolsProfessions1 : list) {
            BizSchoolsDepartment department =bizSchoolsDepartmentMapper.selectBizSchoolsDepartmentById(bizSchoolsProfessions1.getDepartmentId());
            if (department != null && department.getDepartName() != null){
                bizSchoolsProfessions1.setDepartmentName(department.getDepartName());
            }
        }
        return list;
    }

    /**
     * 新增院校展示
     *
     * @param bizSchoolsProfessions 院校展示
     * @return 结果
     */
    @Override
    public int insertBizSchoolsProfessions(BizSchoolsProfessions bizSchoolsProfessions)
    {
        return bizSchoolsProfessionsMapper.insertBizSchoolsProfessions(bizSchoolsProfessions);
    }

    /**
     * 修改院校展示
     *
     * @param bizSchoolsProfessions 院校展示
     * @return 结果
     */
    @Override
    public int updateBizSchoolsProfessions(BizSchoolsProfessions bizSchoolsProfessions)
    {
        return bizSchoolsProfessionsMapper.updateBizSchoolsProfessions(bizSchoolsProfessions);
    }

    /**
     * 批量删除院校展示
     *
     * @param ids 需要删除的院校展示主键
     * @return 结果
     */
    @Override
    public int deleteBizSchoolsProfessionsByIds(Long[] ids)
    {
        return bizSchoolsProfessionsMapper.deleteBizSchoolsProfessionsByIds(ids);
    }

    /**
     * 删除院校展示信息
     *
     * @param id 院校展示主键
     * @return 结果
     */
    @Override
    public int deleteBizSchoolsProfessionsById(Long id)
    {
        return bizSchoolsProfessionsMapper.deleteBizSchoolsProfessionsById(id);
    }

    /**
     * 根据学校ID批量删除院校专业信息（级联删除课程信息）
     *
     * @param ids 学校ID数组
     * @return 结果
     */
    @Override
    public int deleteBizSchoolsProfessionsBySchoolIds(Long[] ids) {
        // 查询所有专业ID
        List<BizSchoolsProfessions> professions = bizSchoolsProfessionsMapper.selectBizSchoolsProfessionsListBySchoolIds(ids);
        if (professions != null && !professions.isEmpty()) {
            for (BizSchoolsProfessions profession : professions) {
                bizSchoolsProfessionsClassesService.inpubdeleteBizSchoolsProfessionsClassesByProfessionId(profession.getId());
            }
        }
        // 删除专业信息
        return bizSchoolsProfessionsMapper.deleteBizSchoolsProfessionsBySchoolIds(ids);
    }

    /**
     * 根据培养计划、目的地、开学时间查询专业列表
     */
    // 实现
    @Override
    public List<BizSchoolsProfessions> selectProfessionsBySearch(Map<String, Object> params) {
        return bizSchoolsProfessionsMapper.selectProfessionsBySearch(params);
    }
}
